package com.ruoyi.web.controller.consume;

import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.consume.domain.CartonApplyTemporaryCon;
import com.ruoyi.consume.service.ICartonApplyTemporaryConService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 纸箱临时领用Controller
 *
 * @author ruoyi
 * @date 2021-07-27
 */
@Api("纸箱临时领用")
@RestController
@RequestMapping("/consume/cartontemap")
public class CartonApplyTemporaryConController extends BaseController
{
    @Autowired
    private ICartonApplyTemporaryConService cartonApplyTemporaryService;

    /**
     * 查询纸箱临时领用列表
     */
    @ApiOperation("查询纸箱临时领用列表")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('consume:cartontemap:list')")
    @GetMapping("/list")
    public TableDataInfo list(CartonApplyTemporaryCon cartonApplyTemporaryCon)
    {
        startPage();
        List<CartonApplyTemporaryCon> list = cartonApplyTemporaryService.selectCartonApplyTemporaryList(cartonApplyTemporaryCon);
        return getDataTable(list);
    }

    /**
     * 导出纸箱临时领用列表
     */
    @PreAuthorize("@ss.hasPermi('consume:cartontemap:export')")
    @Log(title = "纸箱临时领用", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CartonApplyTemporaryCon cartonApplyTemporaryCon)
    {
        List<CartonApplyTemporaryCon> list = cartonApplyTemporaryService.selectCartonApplyTemporaryList(cartonApplyTemporaryCon);
        ExcelUtil<CartonApplyTemporaryCon> util = new ExcelUtil<CartonApplyTemporaryCon>(CartonApplyTemporaryCon.class);
        return util.exportExcel(list, "纸箱临时领用数据");
    }

    /**
     * 获取纸箱临时领用详细信息
     */
    @PreAuthorize("@ss.hasPermi('consume:cartontemap:query')")
    @GetMapping(value = "/{cartonApplyTemporaryId}")
    public AjaxResult getInfo(@PathVariable("cartonApplyTemporaryId") Long cartonApplyTemporaryId)
    {
        return AjaxResult.success(cartonApplyTemporaryService.selectCartonApplyTemporaryById(cartonApplyTemporaryId));
    }

    /**
     * 新增纸箱临时领用
     */
    @PreAuthorize("@ss.hasPermi('consume:cartontemap:add')")
    @Log(title = "纸箱临时领用", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CartonApplyTemporaryCon cartonApplyTemporaryCon)
    {
        return toAjax(cartonApplyTemporaryService.insertCartonApplyTemporary(cartonApplyTemporaryCon));
    }

    /**
     * 修改纸箱临时领用
     */
    @PreAuthorize("@ss.hasPermi('consume:cartontemap:edit')")
    @Log(title = "纸箱临时领用", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CartonApplyTemporaryCon cartonApplyTemporaryCon)
    {
        return toAjax(cartonApplyTemporaryService.updateCartonApplyTemporary(cartonApplyTemporaryCon));
    }

    /**
     * 删除纸箱临时领用
     */
    @PreAuthorize("@ss.hasPermi('consume:cartontemap:remove')")
    @Log(title = "纸箱临时领用", businessType = BusinessType.DELETE)
	@DeleteMapping("/{cartonApplyTemporaryIds}")
    public AjaxResult remove(@PathVariable Long[] cartonApplyTemporaryIds)
    {
        return toAjax(cartonApplyTemporaryService.deleteCartonApplyTemporaryByIds(cartonApplyTemporaryIds));
    }

    /**
     * 更新库存量表
     */
    @ApiOperation("更新库存量表")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('consume:cartontemap:amount')")
    @Log(title = "纸箱临时领用", businessType = BusinessType.UPDATE)
    @PutMapping("/amount")
    public AjaxResult amount(@RequestBody CartonApplyTemporaryCon cartonApplyTemporaryCon)
    {
        return toAjax(cartonApplyTemporaryService.updateAmount(cartonApplyTemporaryCon));
    }

    /**
     * 更新领用状态
     */
    @ApiOperation("更新领用状态")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('consume:cartontemap:consu')")
    @Log(title = "纸箱临时领用", businessType = BusinessType.UPDATE)
    @PutMapping("/consu/{cartonApplyTemporaryId}")
    public AjaxResult consume(@PathVariable("cartonApplyTemporaryId") Long cartonApplyTemporaryId)
    {
        return toAjax(cartonApplyTemporaryService.updateConsumeStatus(cartonApplyTemporaryId));
    }

    /**
     * 退回操作
     */
    @ApiOperation("退回操作")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('consume:cartontemap:back')")
    @Log(title = "纸箱临时领用", businessType = BusinessType.UPDATE)
    @PutMapping("/back/{cartonApplyTemporaryId}")
    public AjaxResult back(@PathVariable("cartonApplyTemporaryId") Long cartonApplyTemporaryId)
    {
        return toAjax(cartonApplyTemporaryService.updateApprovalStatus(cartonApplyTemporaryId));
    }
}
